﻿@model PagedList.IPagedList<VOD.Models.Comment>

<h3>全部评论<span>(</span><span class="CommentCount">@Model.TotalItemCount</span><span>)</span></h3>
@if (Model.TotalItemCount < 1)
{ 
    <p>暂无评论！</p>
}
else
{
<div class="PageNum">
<span class="allNum">第@((Model.PageNumber-1) * Model.PageSize + 1)-@(Model.PageNumber * Model.PageSize)条 共@(Model.Count())条</span>
<span class="PageList">
    @for (var i = 1; i <= Model.PageCount; i++)
    {
        if (i == Model.PageNumber)
        {
            @Ajax.ActionLink(i.ToString(), "Index", "Comment", new { id = ViewBag.VideoID, page = i }, new AjaxOptions { UpdateTargetId = "Comments", HttpMethod = "Get" }, new { @class = "now" })@:&nbsp;
        }
        else
        {
            @Ajax.ActionLink(i.ToString(), "Index", "Comment", new { id = ViewBag.VideoID, page = i }, new AjaxOptions { UpdateTargetId = "Comments", HttpMethod = "Get" })@:&nbsp;
        }
    }
</span>
</div>
<div class="commentList">
@foreach (var comment in Model.Where(m => m.ParentID == null))
{
<dl class="clearfix">
    <dt>
        <img height="40" width="40" src="@Url.Content("~/Content/images/0.jpg")" />
    </dt>
    <dd>
        <p class="info">
        @(comment.UserID == Guid.Empty ? "匿名" : Membership.GetUser(comment.UserID).UserName)
        @comment.PostTime</p>
        <p class="content">@comment.CommentContent</p>
        <p class="interact">
            <a class="replay" href="#comm" data="@comment.CommentID">回复</a>
            @if (Roles.IsUserInRole("Administrators"))
            {
            <a class="btnDelete" data="@comment.CommentID" href="javascript:;">删除</a>
            }
        </p>
        @if (Model.Where(m => m.ParentID == comment.CommentID).Count() > 0)
        {
        <div class="quote">
            <div class="inquote">
            @foreach (var comment2 in Model.Where(m => m.ParentID == comment.CommentID))
            {
                <dl class="clearfix">
                    <dt><img height="20" width="20" src="@Url.Content("~/Content/images/0.jpg")" /></dt>
                    <dd>
                        <p class="info">@(comment2.UserID == Guid.Empty ? "匿名" : Membership.GetUser(comment2.UserID).UserName) @comment2.PostTime</p>
                        <p class="content">@comment2.CommentContent</p>
                        <p class="interact">
                            @if (Roles.IsUserInRole("Administrators"))
                            {
                            <a class="btnDelete" data="@comment2.CommentID" href="javascript:;">删除</a>
                            }
                        </p>
                    </dd>
                </dl>
            }
            </div>
        </div>
        }
    </dd>
</dl>
}

</div>
<div class="PageNum">
<span class="allNum">第@((Model.PageNumber-1) * Model.PageSize + 1)-@(Model.PageNumber * Model.PageSize)条 共@(Model.Count())条</span>
<span class="PageList">
    @for (var i = 1; i <= Model.PageCount; i++)
    {
        if (i == Model.PageNumber)
        {
            @Ajax.ActionLink(i.ToString(), "Index", "Comment", new { id = ViewBag.VideoID, page = i }, new AjaxOptions { UpdateTargetId = "Comments", HttpMethod = "Get" }, new { @class = "now" })@:&nbsp;
        }
        else
        {
            @Ajax.ActionLink(i.ToString(), "Index", "Comment", new { id = ViewBag.VideoID, page = i }, new AjaxOptions { UpdateTargetId = "Comments", HttpMethod = "Get" })@:&nbsp;
        }
    }
</span>
</div>
@Content.Script("jquery.min.js", Url)
<script type="text/javascript">
    $(function () {
        $("a.replay").live("click", function (e) {
            $("#ParentID").val($(e.target).attr("data"));
        });
        $("a.btnDelete").live("click", function (e) {
            if (confirm("确定删除此评论？")) {
                var commentID = $(e.target).attr("data");
                //利用ajax删除评论
                $.ajax({
                    url: "@Url.Content("~/Comment/Delete/")",
                    type: "POST",
                    data: "id=" + commentID,
                    success: function (result) {
                        if (result == "succeed") {
                            alert("删除成功");
                        }
                        else{
                            alert("删除失败");
                        }
                        $("#Comments").load("@Url.Content("~/Comment/Index/"+ViewBag.VideoID)");
                    }
                });
            }
        });
    });
</script>
}